<?php
class Search_Model_Basicjyoken extends Search_Model_Common{

	/**
	* 基本条件取得処理
	*
	* XMLファイルを読み込み基本条件を作成する。
	*
	* @access	public
	* @param	array
	* @return	void
	*/
	public function getBasicJyoken($params)
	{
		$xmlObjs = new stdClass;

		// TODO 読み込みファイルパス(仮)
		$filename = APPLICATION_PATH . '/conf.xml';

		mb_detect_order("SJIS-win,EUCJP-win,UTF-8,JIS,ASCII");

		if ( file_exists($filename)){
			// get xml
			$xmlStr = file_get_contents($filename);
			// parse xml
			$encode = mb_detect_encoding( strip_tags( $xmlStr ) );
			$xmlStr = mb_convert_encoding( $xmlStr, $encode, mb_detect_order() );
			$xmlObjs = @simplexml_load_string( $xmlStr, "SimpleXMLIterator" );
		}

		return $xmlObjs;
	}

	/**
	* 基本条件選択パラメータ反映
	*
	* @access	public
	* @param	array
	* @param	array ※参照渡し
	* @return	void
	*/
	public function convertData($params,&$data)
	{
		if(array_key_exists("BASIC_TYPE", $data['basic'])){

			foreach ($data['basic']->BASIC_TYPE as $xml)
			{
				foreach ($xml->BASIC_DATA->array as $xmlData)
				{
					// パラメータ名取得
					$inputId = (string)$xmlData->INPUT_ID;

					// 項目種類取得
					$type = $xmlData->INPUT_TYPE;

					// セレクトボックス
					if($type == "select"){
						foreach ($xmlData->SELECT_VALUE->array as $select){
							if($this->returnValue($params,$inputId) == $select->VALUE){
								$select->SELECTED = "selected";
							}
						}
					}

					// ラジオボタン
					if($type == "radio" || $type == "checkbox"){
						if($this->returnValue($params,$inputId) == 1){
								$xmlData->CHECKED = "checked";
						}
					}
				}
			}
		}
	}

	public function setChecked($params)
	{
		$data = array();

		// パラメータに基本条件がある場合,選択済みとする
		/* 賃料 */

		//初期費用
		$data['syokihiyo0'] = "checked";
		//if($this->returnValue($params,syokihiyo) == "0"){
		//	$data['syokihiyo0'] = "checked";
		//}
		if($this->returnValue($params,syokihiyo) == "3"){
			$data['syokihiyo3'] = "checked";
			$data['syokihiyo0'] = "";
		}
		if($this->returnValue($params,syokihiyo) == "5"){
			$data['syokihiyo5'] = "checked";
			$data['syokihiyo0'] = "";
		}
		if($this->returnValue($params,syokihiyo) == "7"){
			$data['syokihiyo7'] = "checked";
			$data['syokihiyo0'] = "";
		}
		if($this->returnValue($params,syokihiyo) == "10"){
			$data['syokihiyo10'] = "checked";
			$data['syokihiyo0'] = "";
		}
		if($this->returnValue($params,syokihiyo) == "99"){
			$data['syokihiyo99'] = "checked";
			$data['syokihiyo0'] = "";
		}
		if($this->returnValue($params,syokihiyo) == "w0"){
			$data['syokihiyow0'] = "checked";
			$data['syokihiyo0'] = "";
		}

		//賃料下限
		$data['tinryo1_min'] = "selected";
		if($this->returnValue($params,tinryo1) == 20000){
			$data['tinryo1_20k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 25000){
			$data['tinryo1_25k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 30000){
			$data['tinryo1_30k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 35000){
			$data['tinryo1_35k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 40000){
			$data['tinryo1_40k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 45000){
			$data['tinryo1_45k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 50000){
			$data['tinryo1_50k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 55000){
			$data['tinryo1_55k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 60000){
			$data['tinryo1_60k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 65000){
			$data['tinryo1_65k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 70000){
			$data['tinryo1_70k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 75000){
			$data['tinryo1_75k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 80000){
			$data['tinryo1_80k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 85000){
			$data['tinryo1_85k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 90000){
			$data['tinryo1_90k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 95000){
			$data['tinryo1_95k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 100000){
			$data['tinryo1_100k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 110000){
			$data['tinryo1_110k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 120000){
			$data['tinryo1_120k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 130000){
			$data['tinryo1_130k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 140000){
			$data['tinryo1_140k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 150000){
			$data['tinryo1_150k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 200000){
			$data['tinryo1_200k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 300000){
			$data['tinryo1_300k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 500000){
			$data['tinryo1_500k'] = "selected";
			$data['tinryo1_min'] = "";
		}
		if($this->returnValue($params,tinryo1) == 1000000){
			$data['tinryo1_1m'] = "selected";
			$data['tinryo1_min'] = "";
		}

		//賃料上限
		$data['tinryo2_max'] = "selected";
		if($this->returnValue($params,tinryo2) == 20000){
			$data['tinryo2_20k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 25000){
			$data['tinryo2_25k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 30000){
			$data['tinryo2_30k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 35000){
			$data['tinryo2_35k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 40000){
			$data['tinryo2_40k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 45000){
			$data['tinryo2_45k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 50000){
			$data['tinryo2_50k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 55000){
			$data['tinryo2_55k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 60000){
			$data['tinryo2_60k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 65000){
			$data['tinryo2_65k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 70000){
			$data['tinryo2_70k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 75000){
			$data['tinryo2_75k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 80000){
			$data['tinryo2_80k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 85000){
			$data['tinryo2_85k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 90000){
			$data['tinryo2_90k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 95000){
			$data['tinryo2_95k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 100000){
			$data['tinryo2_100k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 110000){
			$data['tinryo2_110k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 120000){
			$data['tinryo2_120k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 130000){
			$data['tinryo2_130k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 140000){
			$data['tinryo2_140k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 150000){
			$data['tinryo2_150k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 200000){
			$data['tinryo2_200k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 300000){
			$data['tinryo2_300k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 500000){
			$data['tinryo2_500k'] = "selected";
			$data['tinryo2_max'] = "";
		}
		if($this->returnValue($params,tinryo2) == 1000000){
			$data['tinryo2_1m'] = "selected";
			$data['tinryo2_max'] = "";
		}

		//めやす賃料
		$data['normal_tinryo'] = "checked";
		if($this->returnValue($params,meyasu_tinryo) == meyasu){
			$data['meyasu_tinryo'] = "checked";
			$data['normal_tinryo'] = "";
		}
		//管理費・共益費込み
		if($this->returnValue($params,tinryo_jouken2) == on){
			$data['tinryo_jouken2Checked'] = "checked";
		}
		//駐車場代込み
		if($this->returnValue($params,tyusyajyo_komi) == on){
			$data['tyusyajyokomiChecked'] = "checked";
		}
		//仲介手数料
		if($this->returnValue($params,shataku_koujyo) == on){
			$data['shatakukoujyoChecked'] = "checked";
		}
		//敷金礼金０
		if($this->returnValue($params,shikireizero) == on){
			$data['shikireizeroChecked'] = "checked";
		}
		/* 割引サービス */
		//敷金なし
		if($this->returnValue($params,shikikin_nashi) == on){
			$data['shikikin_nashiChecked'] = "checked";
		}
		//礼金なし
		if($this->returnValue($params,reikin_nashi) == on){
			$data['reikin_nashiChecked'] = "checked";
		}
		//フリーレント
		if($this->returnValue($params,freerent) == on){
			$data['freerentChecked'] = "checked";
		}
		//部屋割
		if($this->returnValue($params,heyawari) == on){
			$data['heyawariChecked'] = "checked";
		}
		/* 間取り */
		//ワンルーム
		if($this->returnValue($params,madori10) == on){
			$data['madori10Checked'] = "checked";
		}
		//1K
		if($this->returnValue($params,madori11) == on){
			$data['madori11Checked'] = "checked";
		}
		//1DK,1SDK
		if($this->returnValue($params,madori12) == on){
			$data['madori12Checked'] = "checked";
		}
		//1LDK,1SLDK
		if($this->returnValue($params,madori14) == on){
			$data['madori14Checked'] = "checked";
		}
		//2R,2K
		if($this->returnValue($params,madori21) == on){
			$data['madori21Checked'] = "checked";
		}
		//2DK,2SDK
		if($this->returnValue($params,madori22) == on){
			$data['madori22Checked'] = "checked";
		}
		//2LDK,2SLDK
		if($this->returnValue($params,madori24) == on){
			$data['madori24Checked'] = "checked";
		}
		//3R,3K
		if($this->returnValue($params,madori31) == on){
			$data['madori31Checked'] = "checked";
		}
		//3DK,3SDK
		if($this->returnValue($params,madori32) == on){
			$data['madori32Checked'] = "checked";
		}
		//3LDK,3SLDK
		if($this->returnValue($params,madori34) == on){
			$data['madori34Checked'] = "checked";
		}
		//4R,4K
		if($this->returnValue($params,madori41) == on){
			$data['madori41Checked'] = "checked";
		}
		//4DK,4SDK
		if($this->returnValue($params,madori42) == on){

			$data['madori42Checked'] = "checked";
		}
		//4LDK,4SLDK
		if($this->returnValue($params,madori44) == on){
			$data['madori44Checked'] = "checked";
		}
		//5K～
		if($this->returnValue($params,madori51) == on){
			$data['madori51Checked'] = "checked";
		}
		/*
		 * 人気のこだわり条件
		 */
		if($this->returnValue($params, kodawari_01) == on){
			$data['kodawari_01Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_02) == on){
			$data['kodawari_02Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_03) == on){
			$data['kodawari_03Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_04) == on){
			$data['kodawari_04Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_05) == on){
			$data['kodawari_05Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_06) == on){
			$data['kodawari_06Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_07) == on){
			$data['kodawari_07Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_08) == on){
			$data['kodawari_08Checked'] = "CHECKED";
		}
		if($this->returnValue($params, kodawari_09) == on){
			$data['kodawari_09Checked'] = "CHECKED";
		}
		/*
		 * 人気のこだわり条件
		 */
		/* 建物種別 */
		//賃貸アパート
		if($this->returnValue($params,syubetu1) == on){
			$data['syubetu1Checked'] = "checked";
		}
		//賃貸マンション
		if($this->returnValue($params,syubetu2) == on){
			$data['syubetu2Checked'] = "checked";
		}
		//賃貸一戸建て・借家
		if($this->returnValue($params,syubetu3) == on){
			$data['syubetu3Checked'] = "checked";
		}
		//貸店舗・賃貸事務所
		if($this->returnValue($params,syubetu4) == on){
			$data['syubetu4Checked'] = "checked";
		}
		//駐車場
		if($this->returnValue($params,syubetu5) == on){
			$data['syubetu5Checked'] = "checked";
		}
		
		//人気こだわり
		if($this->returnValue($params,kodawari_01) == on){
		    $data['kodawari_01Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_02) == on){
		    $data['kodawari_02Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_03) == on){
		    $data['kodawari_03Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_04) == on){
		    $data['kodawari_04Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_05) == on){
		    $data['kodawari_05Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_06) == on){
		    $data['kodawari_06Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_07) == on){
		    $data['kodawari_07Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_08) == on){
		    $data['kodawari_08Checked'] = "checked";
		}
		if($this->returnValue($params,kodawari_09) == on){
		    $data['kodawari_09Checked'] = "checked";
		}
		//人気こだわり

		/* 最寄り駅からの時間（徒歩）*/
		//指定なし
		$data['ekitoho0Checked'] = "checked";
		//1分以内
		if($this->returnValue($params,ekitoho) == 1){
			$data['ekitoho1Checked'] = "checked";
			$data['ekitoho0Checked']  = "";
		}
		//5分以内
		if($this->returnValue($params,ekitoho) == 5){
			$data['ekitoho5Checked'] = "checked";
			$data['ekitoho0Checked']  = "";
		}
		//7分以内
		if($this->returnValue($params,ekitoho) == 7){
			$data['ekitoho7Checked'] = "checked";
			$data['ekitoho0Checked']  = "";
		}
		//10分以内
		if($this->returnValue($params,ekitoho) == 10){
			$data['ekitoho10Checked'] = "checked";
			$data['ekitoho0Checked']  = "";
		}
		//15分以内
		if($this->returnValue($params,ekitoho) == 15){
			$data['ekitoho15Checked'] = "checked";
			$data['ekitoho0Checked']  = "";
		}
		//バス利用可
		if($this->returnValue($params,bas_riyou) == on){
			$data['bas_riyouChecked'] = "checked";
		}

		//専有面積下限
		$data['senyu1_min'] = "selected";
		if($this->returnValue($params,senyu1) == 15){
			$data['senyu1_15'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 20){
			$data['senyu1_20'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 25){
			$data['senyu1_25'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 30){
			$data['senyu1_30'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 35){
			$data['senyu1_35'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 40){
			$data['senyu1_40'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 45){
			$data['senyu1_45'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 50){
			$data['senyu1_50'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 60){
			$data['senyu1_60'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 70){
			$data['senyu1_70'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 80){
			$data['senyu1_80'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 90){
			$data['senyu1_90'] = "selected";
			$data['senyu1_min'] = "";
		}
		if($this->returnValue($params,senyu1) == 100){
			$data['senyu1_100'] = "selected";
			$data['senyu1_min'] = "";
		}

		//専有面積上限
		$data['senyu2_max'] = "selected";
		if($this->returnValue($params,senyu2) == 15){
			$data['senyu2_15'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 20){
			$data['senyu2_20'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 25){
			$data['senyu2_25'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 30){
			$data['senyu2_30'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 35){
			$data['senyu2_35'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 40){
			$data['senyu2_40'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 45){
			$data['senyu2_45'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 50){
			$data['senyu2_50'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 60){
			$data['senyu2_60'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 70){
			$data['senyu2_70'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 80){
			$data['senyu2_80'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 90){
			$data['senyu2_90'] = "selected";
			$data['senyu2_max'] = "";
		}
		if($this->returnValue($params,senyu2) == 100){
			$data['senyu2_100'] = "selected";
			$data['senyu2_max'] = "";
		}

		/* 築年数 */
		//指定なし
		$data['built0Checked'] = "checked";
		//新築
		if($this->returnValue($params,built) == 1){
			$data['built1Checked'] = "checked";
			$data['built0Checked'] = "";
		}
		//3年以内
		if($this->returnValue($params,built) == 3){
			$data['built3Checked'] = "checked";
			$data['built0Checked'] = "";
		}
		//5年以内
		if($this->returnValue($params,built) == 5){
			$data['built5Checked'] = "checked";
			$data['built0Checked'] = "";
		}
		//10年以内
		if($this->returnValue($params,built) == 10){
			$data['built10Checked'] = "checked";
			$data['built0Checked'] = "";
		}

		/* 情報の新しさ */
		//指定なし
		$data['jyohou0Checked'] = "checked";
		//本日更新
		if($this->returnValue($params,jyohou) == 1){
			$data['jyohou1Checked'] = "checked";
			$data['jyohou0Checked'] = "";
		}
		//3日以内更新
		if($this->returnValue($params,jyohou) == 3){
			$data['jyohou3Checked'] = "checked";
			$data['jyohou0Checked'] = "";
		}
		//1週間以内
		if($this->returnValue($params,jyohou) == 7){
			$data['jyohou7Checked'] = "checked";
			$data['jyohou0Checked'] = "";
		}

		/* 画像 */
		//内装写真あり
		if($this->returnValue($params,kodawari1) == on){
			$data['kodawari1Checked'] = "checked";
		}
		//パノラマ画像あり
		if($this->returnValue($params,kodawari2) == on){
			$data['kodawari2Checked'] = "checked";
		}

		//2011/03/15 災害支援住宅対応 Start
		//災害支援住宅
		if ($this->returnValue($params,sienJutaku) == "on")
		{
			$data['sienJutakuChecked'] = "checked";
		}
		//2011/03/15 災害支援住宅対応 End
		//2011/04/18 特別優遇物件対応 Start
		//特別優遇物件
		if ($this->returnValue($params,yuguJutaku) == "on")
		{
			$data['yuguJutakuChecked'] = "checked";
		}
		//2011/04/18 特別優遇物件対応 End

		return $data;
	}
}
?>